#TOPDIR	:= $(shell /bin/pwd)

#CFLAGS= -Os -fomit-frame-pointer  -DVIDEO_DEBUG

INC_PATH =  -I//opt/wisermind_MPC83xx/powerpc-e300c3-linux/include

CROSS_COMPILE=/opt/wisermind_MPC83xx/bin/powerpc-e300c3-linux-
CROSS_CFLAGS= -mbig-endian

LIBPATH=/opt/wisermind_MPC83xx/powerpc-e300c3-linux/lib
#CFLAGS= 
#LDFLAGS= -L/opt/wisermind_MPC83xx/powerpc-e300c3-linux/lib -L. $(LIBPATH)/libc.so $(LIBPATH)/libpthread.so -allow-shlib-undefined
#LDFLAGS= -L/opt/wisermind_MPC83xx/powerpc-e300c3-linux/lib -L. $(TOPDIR)/bin/libframe.so
#LDFLAGS= -L/opt/wisermind_MPC83xx/powerpc-e300c3-linux/lib $(LIBPATH)/libc.a $(LIBPATH)/libpthread.a
LDFLAGS= -L/opt/wisermind_MPC83xx/powerpc-e300c3-linux/lib -static $(LIBPATH)/libc.a -static $(LIBPATH)/libpthread.a
#LDFLAGS= -L/usr/lib -L/usr/lib/mysql -L. -lmysqlclient  -lpthread -lc -allow-shlib-undefined
CC = $(CROSS_COMPILE)gcc
CPLUSPLUS = $(CROSS_COMPILE)g++
LD = $(CROSS_COMPILE)ld

#LDFLAGS += CERPATH

CFLAGS += -DDEBUG -D__Linux__ -g  -mpowerpc -msoft-float

#TOPDIR:=$(shell /bin/pwd)

ifeq ($(strip $(TOPDIR)),)
TOPDIR	:= $(shell /bin/pwd)/..
endif

ifeq ($(strip $(BUILD_MYAPP)), static)
CFLAGS += -DBUILD_STATIC
endif

ifeq ($(strip $(BUILD_MYAPP)), debug)
	CFLAGS += -g -static
else
#CFLAGS += -s
endif

SER_BIN = netset
all: per $(SER_BIN) last

CFLAGS += $(INC_PATH) 	
CFLAGS += -I$(TOPDIR)/com_inc -I$(TOPDIR)/sim_inc -I$(TOPDIR)/frame 

SERVEROBJS=a_md5.o crc.o Cryptogram.o des_min_enc.o Manager.o Misc.o NetCheckClient.o NetCheckServer.o NetSet.o SetConfig.o SetMain.o SetServer.o SetState.o SetTree.o TimerClient.o timer.o TimerServer.o  

#SERVEROBJS=SetMain.o  

#FRAMEOBJS = 
FRAMEOBJS = framelist.o CLog.o CAsynchIo.o CBaseMainManage.o  CSqlParmer.o pthreadBaseMain.o seqMsgPool.o RoundSeq.o seqMemPool.o systemFunLinux.o  netIoMemPool.o netIoSeq.o GlobalHelper.o GlobalParm.o pthreadNet.o pthreadWork.o ServerMain.o  ServerTest.o netSocketLinux.o co_mem.o


CLIENTOBJS =Client.o

per:
	cp $(TOPDIR)/frame/*.o ./ 

last:
	cp netset $(TOPDIR)/bin 


$(SER_BIN):$(SER_BIN)ld.o
	$(CPLUSPLUS) $(SER_BIN)ld.o  -o  $(SER_BIN) $(LDFLAGS) $(EXTLDFLAGS)  && ls -l $(SER_BIN) 

$(SER_BIN)ld.o:$(SERVEROBJS) $(FRAMEOBJS) 
	$(LD) $(EXTRA_LDFLAGS) $(LDFLAGS) -r -o $@ $(SERVEROBJS)$(FRAMEOBJS)

%.o: %.c
	$(CC) $(CFLAGS) $(EXTRA_CFLAGS) $(CFLAGS_$@) -c -o $@ $<

%.o: %.cpp
	$(CPLUSPLUS) $(CFLAGS) $(EXTRA_CFLAGS) $(CFLAGS_$@) -c -o $@ $<


clean:
	-rm -f $(SERVEROBJS) $(CLIENTOBJS) netset client *.o *.so
